package com.gqyin.cloud.ai.demo.controller;

import com.gqyin.cloud.ai.demo.service.TongYiService;
import org.springframework.ai.image.ImageResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author guiqing.yin
 * @Date 2024-05-14 16:32
 */
@RestController
@RequestMapping("/tongyi")
@CrossOrigin
public class TongYiController {

    private TongYiService tongYiSimpleService;

    private TongYiService tongYiImagesServiceImpl;

    private TongYiService tongYiAudioServiceImpl;

    @Autowired
    @Qualifier("tongYiSimpleServiceImpl")
    public void setTongYiSimpleService(TongYiService tongYiSimpleService) {
        this.tongYiSimpleService = tongYiSimpleService;
    }

    @Autowired
    @Qualifier("tongYiImagesServiceImpl")
    public void setTongYiImagesServiceImpl(TongYiService tongYiImagesServiceImpl) {
        this.tongYiImagesServiceImpl = tongYiImagesServiceImpl;
    }

    @Autowired
    @Qualifier("tongYiAudioServiceImpl")
    public void setTongYiAudioServiceImpl(TongYiService tongYiAudioServiceImpl) {
        this.tongYiAudioServiceImpl = tongYiAudioServiceImpl;
    }

    @GetMapping("/simple")
    public String completion(@RequestParam(value = "message", defaultValue = "讲个笑话") String message) {
        return tongYiSimpleService.completion(message);
    }

    @GetMapping("/stream")
    public Map<String, String> streamCompletion(@RequestParam(value = "message", defaultValue = "西红柿炖牛腩怎么做？")
                                                String message) {
        return tongYiSimpleService.streamCompletion(message);
    }

    @GetMapping("/image")
    public ImageResponse genImage(@RequestParam(value = "prompt", defaultValue = "画一只哈士奇") String imagePrompt) {
        return tongYiImagesServiceImpl.genImage(imagePrompt);
    }

    @GetMapping("/audio")
    public String genAudio(@RequestParam(value = "prompt", defaultValue = "中华人民共和国万岁") String prompt) {
        return tongYiAudioServiceImpl.genAudio(prompt);
    }
}
